<?php
/**
 * 描述
 * Created by Paco
 * Date: 2018/10/19 Time: 11:40
 */

namespace App\Http\Controllers\Admin\Order;


use App\Http\Controllers\Controller;
use App\Http\Request\Order\RuleStore;
use App\Repositories\Order\RuleRepository;
use Illuminate\Http\Request;

class RuleController extends Controller
{
    protected $rule;

    public function __construct(RuleRepository $rule)
    {
        $this->rule = $rule;
    }

    /**
     *
     * index
     * @author Paco
     * @createTime 2018/10/19 12:13
     * @return \Illuminate\Http\JsonResponse|mixed
     */
    public function index()
    {
        return $this->rule->index();
    }


    /**
     *
     * show
     * @author Paco
     * @createTime 2018/10/19 12:13
     * @param $rule_id
     * @return \Illuminate\Http\JsonResponse|mixed
     */
    public function show($rule_id)
    {
        return $this->rule->show($rule_id);
    }


    /**
     *
     * store
     * @author Paco
     * @createTime 2018/10/19 12:12
     * @param RuleStore $rule
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(RuleStore $rule, Request $request)
    {
        $data = $rule->validated($request);
        return $this->rule->store($data);
    }

    /**
     *
     * save
     * @author Paco
     * @createTime 2018/10/19 12:12
     * @param RuleStore $rule
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function save(RuleStore $rule, Request $request)
    {
        $data = $rule->validated($request);
        return $this->rule->save($data);
    }

    /**
     *
     * del
     * @author Paco
     * @createTime 2018/10/19 12:13
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function del(Request $request)
    {
        $rule_ids = $request->input('rule_ids', 0);
        return $this->rule->del($rule_ids);
    }
}